﻿package mortal.game.view.common.tooltip.tooltips
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.text.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.tooltip.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.palyer.data.*;
    import mortal.game.view.shopMall.view.*;

    public class ToolTipGrowthTalentItem extends ToolTipScaleBg
    {
        protected var _txtType:GTextFiled;
        protected var _txtName:GTextFiled;
        protected var _icon:ShopSellItem;
        protected var _txtLv:AutoLayoutTextContainer;
        protected var _attrTxt:GTextFiled;
        protected var _growthTalentSpr:GSprite;
        protected var _growthAttrInfo:AutoLayoutTextContainer;
        protected var _talentAttrInfo:GTextFiled;
        protected var _txtDesc:GTextFiled;
        protected var _txtTips:GTextFiled;
        protected var _data:ItemData;

        public function ToolTipGrowthTalentItem()
        {
            this.createChildren();
            paddingBottom = 8;
            paddingLeft = 12;
            paddingRight = 8;
            paddingTop = 8;
            return;
        }// end function

        protected function createChildren() : void
        {
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.size = 15;
            _loc_1.bold = true;
            this._txtType = UIFactory.gTextField("", 16, 0, 80, 24, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatPutong;
            _loc_1.size = 15;
            _loc_1.bold = true;
            this._txtName = UIFactory.gTextField("", 16, 0, 288, 24, this, _loc_1);
            this._icon = UICompomentPool.getUICompoment(ShopSellItem);
            this._icon.x = 0;
            this._icon.y = 26;
            this._icon.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this._icon.createDisposedChildren();
            this.addChild(this._icon);
            this._icon.isShowLock = true;
            this._txtLv = new AutoLayoutTextContainer();
            this._txtLv.x = 80;
            this._txtLv.y = 35;
            this._txtLv.addNewText(200, "", 12, 16777215);
            this._txtLv.addNewText(200, "", 12, 16777215);
            this._txtLv.addNewText(200, "", 12, 16777215);
            this._txtLv.verticalGap = -5;
            contentContainer2D.addChild(this._txtLv);
            this._attrTxt = UIFactory.gTextField("", 0, 65 + 34, 140, 20, contentContainer2D);
            this._growthTalentSpr = UICompomentPool.getUICompoment(GSprite);
            this._growthTalentSpr.x = 0;
            this._growthTalentSpr.y = 65 + 20 + 26 + 12;
            contentContainer2D.addChild(this._growthTalentSpr);
            this._growthAttrInfo = new AutoLayoutTextContainer();
            this._growthAttrInfo.x = 0;
            this._growthAttrInfo.y = 0;
            this._growthAttrInfo.verticalGap = -7;
            this._growthTalentSpr.addChild(this._growthAttrInfo);
            this._talentAttrInfo = UIFactory.gTextField("", 0, -5, 120, 20, this._growthTalentSpr, GlobalStyle.textFormatLv);
            this._txtDesc = UIFactory.gTextField("", 0, 115 + 50, 232, 120, contentContainer2D);
            this._txtDesc.multiline = true;
            this._txtDesc.wordWrap = true;
            this._txtTips = UIFactory.gTextField(Language.getString(20248), 0, this._txtDesc.y + 60, 242, 20, contentContainer2D);
            this._txtTips.textColor = 3602685;
            return;
        }// end function

        override public function set data(param1) : void
        {
            var _loc_5:GrowthTalentConsumeData = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:String = null;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:Array = null;
            var _loc_12:int = 0;
            var _loc_13:int = 0;
            var _loc_14:String = null;
            var _loc_15:int = 0;
            this._data = param1 as ItemData;
            if (this._data == null)
            {
                return;
            }
            super.data = this._data;
            setBg(ToolTipUtil.getBgNameByColor(this._data.itemInfo.color));
            _scaleBg.setSize(250, paddingTop + paddingBottom + this._txtDesc.y + this._txtDesc.textHeight + 8);
            var _loc_2:* = ItemsUtil.isBind(this._data);
            this._icon.itemData = this._data;
            this._icon.isBind = _loc_2;
            if (this._data.itemInfo.category == EStuff._EStuffJewel)
            {
                this._txtLv.setText(0, Language.getStringByParam(20243, this._data.itemInfo.itemLevel));
            }
            else
            {
                this._txtLv.setText(0, Language.getStringByParam(20243, this._data.itemInfo.level));
            }
            this._txtLv.setText(1, Language.getStringByParam(20244, ColorConfig.instance.getItemColor(this._data.itemInfo.color).colorText));
            var _loc_3:* = this._data.itemInfo.beginDate.time;
            var _loc_4:* = this._data.itemInfo.endDate.time;
            if (_loc_3 == _loc_4)
            {
                if (this._data.extData is GrowthTalentConsumeData)
                {
                    _loc_5 = this._data.extData;
                }
                else
                {
                    _loc_5 = ItemsUtil.getGrowthTalentInfo(this._data);
                }
                _loc_6 = _loc_5.hasUseNum;
                _loc_7 = _loc_5.currMaxNum;
                _loc_8 = HTMLUtil.addColor(Language.getStringByParam(20787, _loc_6, _loc_7), GlobalStyle.colorLv);
                this._txtLv.setText(2, _loc_8);
            }
            else
            {
                _loc_9 = ClockManager.instance.nowDate.time;
                if (_loc_9 >= _loc_3 && _loc_9 < _loc_4)
                {
                    this._txtLv.setText(2, Language.getString(20245));
                }
                else
                {
                    this._txtLv.setText(2, Language.getString(20245) + Language.getString(20246));
                }
            }
            switch(this._data.itemInfo.type)
            {
                case EAdvanceType._EAdvanceTypeFashionClothesGrowth:
                case EAdvanceType._EAdvanceTypeFashionClothesTalent:
                {
                    this._attrTxt.text = Language.getString(20788);
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionWingGrowth:
                case EAdvanceType._EAdvanceTypeFashionWingTalent:
                {
                    this._attrTxt.text = Language.getString(20789);
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionWeaponGrowth:
                case EAdvanceType._EAdvanceTypeFashionWeaponTalent:
                {
                    this._attrTxt.text = Language.getString(20790);
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionFightSoulGrowth:
                case EAdvanceType._EAdvanceTypeFashionFightSoulTalent:
                {
                    this._attrTxt.text = Language.getString(20791);
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionFightMethodGrowth:
                case EAdvanceType._EAdvanceTypeFashionFightMethodTalent:
                {
                    this._attrTxt.text = Language.getString(20792);
                    break;
                }
                case EAdvanceType._EAdvanceTypeFashionDragonSoulGrowth:
                case EAdvanceType._EAdvanceTypeFashionDragonSoulTalent:
                {
                    this._attrTxt.text = Language.getString(20793);
                    break;
                }
                case EAdvanceType._EAdvanceTypeMountGrowth:
                case EAdvanceType._EAdvanceTypeMountTalent:
                {
                    this._attrTxt.text = Language.getString(20794);
                    break;
                }
                case EAdvanceType._EAdvanceTypePet2Growth:
                case EAdvanceType._EAdvanceTypePet2Talent:
                {
                    this._attrTxt.text = Language.getString(20795);
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (ItemsUtil.isGrowthStuff(this._data))
            {
                _loc_10 = this._growthAttrInfo.numChildren;
                _loc_11 = ItemsUtil.getGrowthItemGainAttr(this._data);
                _loc_12 = _loc_11.length - _loc_10;
                if (_loc_12 > 0)
                {
                    _loc_13 = 0;
                    while (_loc_13 < _loc_12)
                    {
                        
                        this._growthAttrInfo.addNewText(150, "", 12, GlobalStyle.colorLvUint);
                        _loc_13++;
                    }
                }
                else if (_loc_12 < 0)
                {
                    this._growthAttrInfo.split(_loc_11.length);
                }
                _loc_13 = 0;
                while (_loc_13 < _loc_11.length)
                {
                    
                    _loc_14 = AttributeUtil.transferAttrName(_loc_11[_loc_13].name);
                    this._growthAttrInfo.setText(_loc_13, _loc_14 + " + " + _loc_11[_loc_13].value);
                    _loc_13++;
                }
            }
            else
            {
                _loc_13 = 0;
                while (_loc_13 < this._growthAttrInfo.numChildren)
                {
                    
                    this._growthAttrInfo.setText(_loc_13, "");
                    _loc_13++;
                }
            }
            if (ItemsUtil.isTalentStuff(this._data))
            {
                _loc_15 = this._data.itemInfo.effectEx;
                this._talentAttrInfo.text = Language.getStringByParam(20796, _loc_15);
            }
            else
            {
                this._talentAttrInfo.text = "";
            }
            if (this._data.itemInfo.alyDesc() != null)
            {
                this._txtDesc.htmlText = this._data.itemInfo.alyDesc();
            }
            else
            {
                this._txtDesc.htmlText = "";
            }
            this._txtDesc.height = this._txtDesc.textHeight + 7;
            this._txtDesc.y = this._growthTalentSpr.y + this._growthTalentSpr.height;
            this.updateName();
            this._txtTips.y = this._txtDesc.y + this._txtDesc.height;
            this.updateBg();
            return;
        }// end function

        public function setBuyback(param1:int) : void
        {
            var _loc_2:String = null;
            var _loc_3:Boolean = false;
            if (param1 < 0)
            {
                this._txtTips.text = Language.getString(20248);
                this._txtTips.textColor = 3602685;
            }
            else
            {
                _loc_2 = GameDefConfig.instance.getEPrictUnitName(this._data.itemInfo.sellUnit);
                _loc_3 = Cache.instance.role.enoughMoney(this._data.itemInfo.sellUnit, param1);
                if (!_loc_3)
                {
                    this._txtTips.textColor = 16711680;
                }
                else
                {
                    this._txtTips.textColor = 65280;
                }
                this._txtTips.text = Language.getStringByParam(20260, param1.toString() + _loc_2);
            }
            return;
        }// end function

        public function updateBg() : void
        {
            _scaleBg.setSize(250, this._txtTips.y + 20 + paddingBottom + paddingTop);
            return;
        }// end function

        override public function get width() : Number
        {
            return _scaleBg.width;
        }// end function

        override public function get height() : Number
        {
            return _scaleBg.height;
        }// end function

        protected function updateName() : void
        {
            this._txtName.width = _scaleBg.width;
            var _loc_1:* = GameDefConfig.instance.getECategory(this._data.itemInfo.category);
            var _loc_2:* = Language.getString(20797);
            if (_loc_1 != null)
            {
                _loc_2 = _loc_1.text;
            }
            this._txtName.htmlText = "[" + _loc_2 + "]  " + this._data.itemInfo.htmlName;
            return;
        }// end function

    }
}
